$import("com.hh.workflow.designer.WorkFlowListTree");
Ext
		.define(
				'com.hh.workflow.designer.WorkFlowDesigner',
				{
					extend : 'com.hh.base.BaseWindow',
					title : '流程设计',
					layout : 'border',
					form_id : null,
					constructor : function(config) {
						this.config = config || {};
						this.superclass.constructor.call(this, this.config);
						this.init();
						var mainPanel = this.createMainPanel();
						var workFlowListTree = this.createWorkFlowListTree();
						this.panel.add(workFlowListTree);
						this.panel.add(mainPanel);
					},
					showEvent : function() {
						Doing.hidden(false);
					},
					createWorkFlowListTree : function() {
						var page = this;
						var workFlowListTree = this.workFlowListTree = Ext
								.create(
										'com.hh.workflow.designer.WorkFlowListTree',
										{
											getTreePanelListeners : function() {
												return {
													itemclick : function(view,
															record, item) {
														if (record.get("leaf")) {
															var iframe = window.frames[page.iframeid];
															var object = Request
																	.synRequestObject(
																			'workflow-WorkFlowInfo-findObjectByDataId',
																			{
																				dataId : record
																						.get("id")
																			});
															var graph = iframe.mxDocument.graph;
															iframe.dataId = record
																	.get("id");
															iframe.workflowName = record
																	.get("text");
															if (object != null) {
																iframe.objectId = object.id;
																var mxgraphXml = object.mxgraphXml;
																var xml = iframe
																		.createXml(mxgraphXml);
																var dec = new iframe.mxCodec(
																		xml.documentElement.ownerDocument);
																dec
																		.decode(
																				xml.documentElement,
																				graph
																						.getModel());
															} else {
																iframe.objectId = '';
																var xml = iframe
																		.createXml('<mxGraphModel><root><Workflow label="'
																				+ record
																						.get("text")
																				+ '" description="" href="" id="0" hrefParams="" data="{}"><mxCell/></Workflow><Layer label="Default Layer" id="1"><mxCell parent="0"/></Layer></root></mxGraphModel>');
																var dec = new iframe.mxCodec(
																		xml.documentElement.ownerDocument);
																dec
																		.decode(
																				xml.documentElement,
																				graph
																						.getModel());
															}
														}
													}
												}
											}
										});
						return workFlowListTree;
					},
					createMainPanel : function() {
						this.iframeid = UUID.getUUID();
						var page = this;
						this.mainPanel = Ext
								.create(
										'Ext.panel.Panel',
										{
											padding : '1',
											tools : [ {
												type : 'refresh',
												handler : function(c, t, tool) {
													window.frames[page.iframeid].location.reload();
												}
											} ],
											icon : 'struts-image?path=com/hh/workflow/img/computer2_16x16.gif',
											autoScroll : true,
											region : 'center',
											title : '设计器',
											html : '<iframe id="'
													+ page.iframeid
													+ '"  name="'
													+ page.iframeid
													+ '"  width=100% height=100%  frameborder=0 src="jsp/workfloweditor.jsp?theme='
													+ theme + '" ></iframe>',
											listeners : {
												beforeDestroy : function(panel) {
													var iframe = document
															.getElementById(page.iframeid);
													iframe.src = "about:blank";
													iframe.parentElement
															.removeChild(iframe);
												}
											}
										});
						return this.mainPanel;
					}
				});